package edu.guet.cn.blogbasics.utils;

import org.springframework.stereotype.Repository;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Auther: hejianding
 * @Date: 2021/4/24 23:16
 * @Version: 1.0
 */
@Repository
public class DateFormUtils {
    /*public static void main(String[] args) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");//yyyy-MM-dd HH:mm:ss
        String timestamp= "1616138930";
        long date_temp = Long.valueOf(timestamp);
        String date_string = sdf.format(new Date(date_temp * 1000L));
        System.out.println(date_string);
    }*/
    //时间戳转日期格式
    public  String DateForm(String timestamp){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");//yyyy-MM-dd HH:mm:ss
        long date_temp = Long.valueOf(timestamp);
        String date_string = sdf.format(new Date(date_temp * 1000L));
        System.out.println(date_string);
        return date_string;
    }
    //日期格式转时间戳
    public Date getDate() {
        String dateStr =  "2021-03-24";
        Date date=new Date();
        try {
            date = new SimpleDateFormat("yyyy-MM-dd").parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
